<script type="text/javascript">
    function ajaxQuickUpdate(id){
        var status = 0;        
        if($("#status_" + id).is(":checked")){ status = 1; }
                
        var strUrl = "<?php echo Url::createUrl("iconSmsKute/ajaxQuickUpdateCategory");?>";
        $.ajax({
            type: "POST",
            url: strUrl,
            data: {
                position : $("#position_"+id).val(),                
                status:status,                
                id:id
            },
            success: function(msg){
                if(msg == 1){
                    alert('Sửa thành công');
                    location.reload();
                }else{
                    alert(msg);
                }
            }          
        });
    }
    function ajaxDelete(id){
        var strUrl = "<?php echo Url::createUrl("iconSmsKute/ajaxDeleteCategory") ?>";
        if(confirm("Bạn có muốn tiếp tục không?")){
            $.ajax({
                type: "POST",
                url: strUrl,
                data: {
                    id:id
                },
                success: function(msg){
                    if(msg == 1){
                        alert('Xóa thành công');
                        location.reload();
                    }else{
                        alert(msg);
                    }
                }          
            });
        }
    }
</script>
<div class="main clearfix">
    <div class="Tabs clearfix">
        <ul class="clearfix">            
            <li><a href="<?php echo Url::createUrl("appSmsKute/index");?>"><span>App Sms Kute</span></a></li>
            <li><a href="<?php echo Url::createUrl("iconSmsKute/index");?>"><span>Biểu tượng</span></a></li>            
            <li><a href="<?php echo Url::createUrl("iconSmsKute/category");?>" class="active"><span>Danh mục biểu tượng</span></a></li>
        </ul>                
    </div>

    <div class="box">
        <div class="fillter clearfix">
            <div class="fl">
                [ <a href="<?php echo Url::createUrl("iconSmsKute/addCategory");?>"><strong>Thêm danh mục mới</strong></a> ]
            </div>
            <div class="fr">
                <ul class="paging">
                    <?php
                        $current_url = Common::getCurrentUrl();
                        $path_paging = strpos($current_url, '?') !==false ? $current_url.'&' : $current_url.'?';
                        $path_paging = str_replace("?page=".$currentPage."&","?",$path_paging);
                        $path_paging = str_replace("&page=".$currentPage."&","&",$path_paging);
                        echo Paging::show_paging_cp($numberPage, $currentPage, $path_paging);
                    ?>
                </ul>
            </div>
        </div>
        <div class="table clearfix">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tbody>
                    <tr class="bg-grey">

                        <td width="60%"><strong>Tên danh mục</strong></td>
                        <td width="10%"><strong>Tình trạng</strong></td>
                        <td width="15%"><strong>Vị trí</strong></td>
                        <td width="15%"><strong>Hành động</strong></td>
                    </tr>
                    
                    <?php foreach($category as $row) { ?>
                    <tr>
                        <td class="middle"><?php echo $row["title"];?></td>
                        <td>
                            <input type="checkbox" value="1" id="status_<?php echo $row["id"]?>" <?php if($row["status"]==1) echo "checked";?> > Hiển thị
                        </td>
                        <td class="middle">
                            <input type="text" id="position_<?php echo $row["id"]?>" value="<?php echo $row["position"];?>" style="width:30px;margin-right:10px"/>                            
                        </td>
                        <td class="middle">
                            <a href="javascript:" onclick="ajaxQuickUpdate(<?php echo $row["id"];?>)"> Lưu </a> | 
                            <a href="<?php echo Url::createUrl("iconSmsKute/editCategory", array("id"=>$row["id"]));?>"> Sửa </a> | 
                            <a href="javascript:" onclick="ajaxDelete(<?php echo $row["id"];?>)"> Xóa </a> 
                        </td>
                    </tr>
                    <?php } ?>
                    
                </tbody>
            </table>
        </div>
        <div class="fillter clearfix">
            <div class="fr">
                <ul class="paging">
                    <?php                        
                        echo Paging::show_paging_cp($numberPage, $currentPage, $path_paging);
                    ?>
                </ul>
            </div>
        </div>

    </div>
</div>